package com.cty.mapper;

import com.cty.pojo.Teacher;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Auther: cty
 * @Date: 2020/3/1 22:41
 * @Description:  MyBatis注解
 * @version: 1.0
 */
public interface TeacherMapper {
    // 5 MyBatis注解实现<resultMap>功能：关联单个对象（N+1方式）
    @Select("select * from teacher where tno=#{0}")
    Teacher selByTno(String tno);

    // 7 MyBatis注解实现<resultMap>功能：关联集合对象（N+1方式）
    @Results(value = {
            @Result(id = true, column = "tno", property = "tno"),
            @Result(column = "tname", property = "tname"),
            @Result(column = "tno", property = "studentList", many = @Many(
                    select = "com.cty.mapper.StudentMapper.selByTno"
            ))
    })
    @Select("select * from teacher")
    List<Teacher> selTeacher();
}
